package tongwentongshu.com.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import tongwentongshu.com.app.R;
import tongwentongshu.com.app.bean.MessageReadBean;

/**
 * Created by Administrator on 2016/2/23.
 */
public class MessageAdapter extends BaseAdapter {
    private Context context;
    private MessageReadBean list;

    public MessageAdapter(Context context, MessageReadBean list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.view_message, null);
            holder = new ViewHolder();
            holder.title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.msg = (TextView) convertView.findViewById(R.id.tv_msg_notice_content);
            holder.time = (TextView) convertView.findViewById(R.id.tv_msg_notice_time);
            holder.iv = (ImageView) convertView.findViewById(R.id.iv_msg_notice);
            holder.dot = (ImageView) convertView.findViewById(R.id.iv_red_dot);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == 0) {
            holder.iv.setImageResource(R.drawable.msg_notice);
            holder.title.setText("通知消息");
            holder.msg.setText(list.getData().getSystem_title());
            holder.time.setText(list.getData().getSystem_time());
            if (list.getData().getIs_system() == 1) {
                holder.dot.setVisibility(View.VISIBLE);
            } else {
                holder.dot.setVisibility(View.GONE);
            }
        } else if (position == 1) {
            holder.iv.setImageResource(R.drawable.msg_interaction);
            holder.title.setText("互动消息");
            holder.msg.setText(list.getData().getInteraction_title());
            holder.time.setText(list.getData().getInteraction_time());
            if (list.getData().getIs_interaction() == 1) {
                holder.dot.setVisibility(View.VISIBLE);
            } else {
                holder.dot.setVisibility(View.GONE);
            }
        }

        return convertView;
    }

    public class ViewHolder {
        private TextView title, msg, time;
        private ImageView iv, dot;
    }

}
